package com.huayue.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.support.spring.FastJsonJsonView;
import com.huayue.annotation.LogAnno;
import com.huayue.entity.Customer;
import com.huayue.entity.RoomStatus;
import com.huayue.service.CustomerService;
import com.huayue.service.RoomStatusService;
import com.huayue.service.RoomTypeService;
import com.huayue.util.PageHelper;

/**
 * 房态
 */
@Controller
@RequestMapping("/room_status")
public class RoomStatusController {
    @Autowired
    RoomStatusService svc;
    @Autowired
    CustomerService csvc;

    @Autowired
    RoomTypeService rtsvc;

    BaseController bc = new BaseController();

    @RequestMapping("/toAdd")
    public ModelAndView toAdd() {
        FastJsonJsonView view = new FastJsonJsonView();
        view.addStaticAttribute("code", 0);
        view.addStaticAttribute("room", svc.findStatus2NoCustomer());
        return new ModelAndView(view);
    }

    @LogAnno(operateType = "补充-房客信息")
    @RequestMapping("/supplement")
    public ModelAndView supplement(Customer customer, String roomId) {
        FastJsonJsonView view = new FastJsonJsonView();
        int i = csvc.addBasic(customer, roomId);
        // i = i + svc.updateCustomerByRoomId(roomId);
        view.addStaticAttribute("code", 0);
        if (i == 1) {
            view.addStaticAttribute("icon", 1);
            view.addStaticAttribute("msg", "补充信息成功");
        } else {
            view.addStaticAttribute("icon", 2);
            view.addStaticAttribute("msg", "补充信息失败");
        }
        return new ModelAndView(view);
    }

    @LogAnno(operateType = "添加-客房信息")
    @RequestMapping("/add")
    public ModelAndView add(RoomStatus rstatus) {
        return bc.add(svc, rstatus);
    }

    @LogAnno(operateType = "修改-客房信息")
    @RequestMapping("/update")
    public ModelAndView update(RoomStatus rstatus) {
        return bc.update(svc, rstatus);
    }

    @LogAnno(operateType = "删除-客房信息")
    @RequestMapping("/delete")
    public ModelAndView delete(RoomStatus rstatus) {
        return bc.delete(svc, rstatus);
    }

    @RequestMapping("/findOne")
    public ModelAndView findOne(RoomStatus rstatus) {
        return bc.findOne(svc, rstatus);
    }

    @RequestMapping("/findPage")
    public ModelAndView findPage(PageHelper page, RoomStatus rstatus) {
        return bc.findPage(svc, page, rstatus, rstatus);
    }

    @RequestMapping("/findRoomInfo")
    public ModelAndView findRoomInfo(String checkDate) {
        // 根据选中的这一天查询改天的房间状态
        FastJsonJsonView view = new FastJsonJsonView();
        view.addStaticAttribute("code", 0);
        view.addStaticAttribute("roomType", rtsvc.findAll());
        view.addStaticAttribute("typeCounts", svc.findAllRoomStatusType(checkDate));
        view.addStaticAttribute("room", svc.findAllRoomStatus(checkDate));
        return new ModelAndView(view);
    }

    @RequestMapping("/toUpdate")
    public ModelAndView findRoomStatusByRoomId(String id) {
        FastJsonJsonView view = new FastJsonJsonView();
        view.addStaticAttribute("code", 0);
        view.addStaticAttribute("type", svc.findAllStatusTypeInfo());
        view.addStaticAttribute("room", svc.findStatusByRoomId(id));
        return new ModelAndView(view);
    }

}
